package com.lipei.vrp.imp;

import java.util.ArrayList;

import org.apache.commons.lang3.StringUtils;

import com.lipei.vrp.AlgorithmType;
import com.lipei.vrp.Context;
import com.lipei.vrp.IAlgorithm;
import com.lipei.vrp.IAlgorithmCreator;

public class VRP_ej implements IAlgorithmCreator {
	private class Impl extends AbstractAlgorithm implements IAlgorithm {
		public Impl(String[] args) {
			super(args);
			if (args.length != 5) {
				throw new RuntimeException(
						"argument should be vrp_ej name number number number");
			}

			if (StringUtils.equals(args[4], "0")) {
				m = 0;
				algtype = AlgorithmType.EJM0;
			} else if (StringUtils.equals(args[4], "1")) {
				m = 1;
				algtype = AlgorithmType.EJM1;
			} else {
				throw new RuntimeException("m value must be 0 or 1");
			}

		}

		@Override
		public ArrayList<String> generateCommand(String vrppath) {
			ArrayList<String> commands = new ArrayList<String>();
			commands.add(Context.ejpath);
			commands.add("-f");
			commands.add(vrppath);
			commands.add("-j");
			commands.add(args[2]);
			commands.add("-t");
			commands.add(args[3]);
			commands.add("-m");
			commands.add(args[4]);

			String command = Context.ejpath + " -f \"" + vrppath + "\" -j "
					+ args[2] + " -t " + args[3] + " -m " + args[4];
			return commands;
		}
	}

	@Override
	public IAlgorithm argsCheck(String[] args) {
		return new Impl(args);
	}

	public static IAlgorithmCreator createIns() {
		// TODO Auto-generated method stub
		return new VRP_ej();
	}
}
